package Panels;

public class WindowStack<A> {
	
	protected class MyNode<B>{
		private B value;
		private MyNode<B> next;
		
		public MyNode(B pValue, MyNode<B> pNext){
			value = pValue;
			next = pNext;
		}
		
		public MyNode<B> getNext(){
			return next;
		}
		
		public void setNext(MyNode<B> pNext){
			this.next = pNext;
		}
		
		public B getValue(){
			return value;
		}
	}
	
	
	private MyNode<A> topNode;
	
	public WindowStack(){
		topNode = null;
	}
	
	public boolean isEmpty(){
		return (topNode == null);
	}
	
	public void push(A pContent){
		
		MyNode<A> tmp = new MyNode<A>(pContent, topNode);//new MyNode<A>(null, null);
		this.topNode = tmp;
	}
	
	public void pop(){
		if(!this.isEmpty()){
			MyNode<A> tmp = topNode;
			topNode = topNode.getNext();
			tmp.setNext(null);
		}
	}
	
	public A top(){
		if(!this.isEmpty()){
			return topNode.getValue();
		}else{
			return null;
		}
	}
	
}
